<?php

/*
 * session.php
 *
 * Legacy file.
 * session handling moved to the Session class
 */


require_once dirname(__FILE__) . '/WideSession.class.php';
// The WideSession is pretty much is self contained.
$session = new WideSession(); // the new session also starts the php session

//THIS IS OLD CODE!
/*

  session_name("wideCMS");
  session_start();



  //DATA
  $userlist = unserialize(@file_get_contents(_SETTINGSPATH_ . "/userdata.ser"));
  $usergroups = unserialize(@file_get_contents(_SETTINGSPATH_ . "/usergroups.ser"));



  if (DEBUG)
  {
  if (empty($userlist))
  { // If the userlist is empty - reset user data
  $_GET['resetuserdata'] = true;
  }
  if (empty($usergroups))
  { // If the userlist is empty - reset user data
  $_GET['resetusergroups'] = true;
  }
  // ITS A DEBUG THING
  require __ADMIN_DIR__ . "/inc/sessiondefaults.php";
  }




  //LOGIC
  if (isset($_GET['logout']) || session_name() != "wideCMS")
  {
  session_destroy();
  header("Location:.");
  }

  if (empty($_SESSION['user']))
  {

  if (!empty($_POST['usr']))
  { // If usr has been send
  if (!empty($userlist[strtolower($_POST['usr'])]))
  { // check userlist for username
  if ($userlist[$_POST['usr']]['password'] == sha1($_POST['pwd']))
  { // if user was found and the password patch
  $_SESSION['username'] = $_POST['usr'];
  $_SESSION['user'] = $userlist[$_POST['usr']];
  }
  else
  { // if wrong pass
  $smarty->assign("msg", "Forkert adgangskode");
  }
  }
  else
  { // if wrong user
  $smarty->assign("msg", "Forkert brugernavn");
  }
  }
  }
  else
  {
  // Refresh permissions each page refresh

  $_SESSION['user']['permissions'] = $usergroups[$userlist[$_SESSION['username']]['permissions']['id']];
  }



 */

//TEMPLATE STUFF

if (!$session->loggedin() || $session->user()->getCurrentUser() == 'guest')
{
    $smarty->assign("request_url", $_SERVER['REQUEST_URI']);
    $smarty->assign("template", "cms.login.tpl");
    $smarty->display($display_template);
    exit();
}
?>